<?php
class MoncuesController extends AppController {

	var $name = 'Moncues';

	function index() {
		$this->Moncue->recursive = 0;
		$this->set('moncues', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid moncue', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('moncue', $this->Moncue->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Moncue->create();
			if ($this->Moncue->save($this->data)) {
				$this->Session->setFlash(__('The moncue has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The moncue could not be saved. Please, try again.', true));
			}
		}
		$mons = $this->Moncue->Mon->find('list');
		$this->set(compact('mons'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid moncue', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Moncue->save($this->data)) {
				$this->Session->setFlash(__('The moncue has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The moncue could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Moncue->read(null, $id);
		}
		$mons = $this->Moncue->Mon->find('list');
		$this->set(compact('mons'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for moncue', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Moncue->delete($id)) {
			$this->Session->setFlash(__('Moncue deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Moncue was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
